/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Connection.DataAccess;
import Model.HoaDon;
import Model.PhieuNhapHang;

/**
 *
 * @author My PC
 */
public class PhieuNhapController {
     public static boolean ThemHD(PhieuNhapHang pnh)
    {
        try 
        {
           String sql = "INSERT INTO tblPhieuNhapHang (MA_PHIEUNHAP, MA_NCC, "
                   + "MA_NHANVIEN,NGAY_NHAPHANG) "
                   + "values (N'"+pnh.getMaPhieu()+"',N'"+pnh.getMaNCC()+"',"
                   + "N'"+pnh.getMaNhanvien()+"',"
                   + "'"+pnh.getNgaylap()+"')";    
           DataAccess da=new DataAccess();
           da.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
     public static boolean XoaHD(PhieuNhapHang pnh)
    {
        try 
        {
            
           String sql = "delete from tblPhieuNhapHang where MA_PHIEUNHAP =N'"+pnh.getMaPhieu()+"'";
           DataAccess da=new DataAccess();
           da.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
     
      public static boolean UpdTongTien(PhieuNhapHang pnh)
     {
         try 
        {
              String sql = "UPDATE tblPhieuNhapHang SET TONGITEN = (SELECT SUM(THANHTIEN)"
                      + "FROM tblChiTietPhieuNhapHang WHERE MA_PHIEUNHAP = N'"+pnh.getMaPhieu()+"' "
                      + "GROUP BY MA_PHIEUNHAP WHERE MA_PHIEUNHAP = N'"+pnh.getMaPhieu()+"'";
           DataAccess da=new DataAccess();
           da.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            return false;
        } 
     }
      
    public static boolean SuaHD(PhieuNhapHang pnh)
    {
        try 
        {
            
           String sql = "UPDATE tblPhieuNhapHang SET MA_NHANVIEN = N'"+pnh.getMaNhanvien() +"',"
                   + " MA_NHACUNGCAP = N'"+pnh.getMaNCC()+"',"
                   + "NGAYLAP = '"+pnh.getNgaylap()+"' WHERE "
                   + "MA_PHIEUNHAP = N'"+pnh.getMaPhieu()+"'";
           DataAccess da=new DataAccess();
           da.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
    
    
}
